package Map集合;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;

/*
* 集合嵌套之ArrayList嵌套HashMap
* 每个HashMap的键和值都是String
* */
public class 集合嵌套1 {
    public static void main(String[] args) {
        /*创建ArrayList集合*/
        ArrayList<HashMap<String, String>> arrayList = new ArrayList<>();
        /*创建HashMap集合，并添加键值对元素*/
        HashMap<String, String> hm1 = new HashMap<String,String>();
        hm1.put("孙策","大乔");
        hm1.put("周瑜","小乔");
        /*把HashMap作为元素添加到ArrayList集合*/
        arrayList.add(hm1);

        HashMap<String, String> hm2 = new HashMap<>();
        hm2.put("郭靖","黄蓉");
        hm2.put("杨过","小龙女");
        /*把HashMap作为元素添加到ArrayList集合*/
        arrayList.add(hm2);

        HashMap<String, String> hm3 = new HashMap<>();
        hm3.put("令狐冲","任盈盈");
        hm3.put("林平之","岳灵珊");
        /*把HashMap作为元素添加到ArrayList集合*/
        arrayList.add(hm3);

        /*遍历ArrayList集合*/
        for (HashMap<String,String> hm:arrayList) {
            Set<String> keySet = hm.keySet();
            for (String key:keySet) {
                String value = hm.get(key);
                System.out.println(key+","+value);
            }
        }
    }
}